cd "${mystart}/Simulated data\Calibration/Benchmark Data/"


*Tables 37 and 39 - treat and pay
qui{
clear
use "Data files/Benchmark.dta"
keep if age<65
keep if TR==0 & ESHI==0
keep if s_record==1 | du_record==1 | dp_record==1

tabstat I_treat
gen I_negligible_MC=1 if MC<500
replace I_negligible_MC=0 if MC>=500

replace OOP=0 if I_treat == 0 | I_pay == 0
egen tot_OOP= total(OOP) if MC>=500
egen tot_MC= total(MC*.6) if MC>=500
gen ratio=tot_OOP/tot_MC

replace I_pay=. if MC<500

* TABLE WITH 3 THINGS, LIMITING TO THE COMPLETELY UNINSURED WITH REPORTED SHOCK
* 1. % WITH MC<$500
* 2. % WITH OOP<.6*MC IF MC>500
* 3. mean(OOP)/mean(MC) IF MC>500 	
tabstat I_negligible_MC  // note this is the same as tabstat I_treat
tabstat I_pay  //if MC>=500 // we want the fraction not paying, so 1 minus this. 
tabstat ratio 
label var ratio "OOP/Charges if treat"
label var I_treat "% treat"
label var I_pay "% pay if treat"

* Table 37 
gen All=1
table  (All) ,  statistic(mean I_treat) statistic(mean I_pay) statistic(mean ratio)  nototals nformat(%5.2f)  
collect title "Model"
collect export "${out_tables}/MC_stats.tex", tableonly replace

* Table 39 
table  (age_group)  ,  statistic(mean I_treat) statistic(mean I_pay) nototals nformat(%5.2f)  
collect title "Model"
collect export "${out_tables}/MC_stats_age.tex", tableonly replace
}
	
	
* Tables 38	and 40
qui{
clear
use "Data files/Benchmark.dta"
keep if age<65
keep if TR==0 & ESHI==0
keep if s_record==1 | du_record==1 | dp_record==1

tabstat I_treat
gen I_negligible_MC=1 if MC<500
replace I_negligible_MC=0 if MC>=500

replace OOP=0 if I_treat == 0 | I_pay == 0
bysort H: egen tot_OOP= total(OOP) if MC>=500
bysort H: egen tot_MC= total(MC*.6) if MC>=500
gen ratio=tot_OOP/tot_MC

replace I_pay=. if MC<500

label var ratio "OOP/Charges if treat"
label var I_treat "% treat"
label var I_pay "% pay if treat"

* Table 38 - bottom panel
gen All=1
table  (H) ,  statistic(mean I_treat) statistic(mean I_pay) statistic(mean ratio)  nototals nformat(%5.2f)  
collect title "Model"
collect export "${out_tables}/MC_stats_H.tex", tableonly replace

* Table 40
table  (age_group) H ,  statistic(mean I_treat)  nototals nformat(%5.2f)  
collect title "Model"
collect export "${out_tables}/MC_stats_age_H.tex", tableonly replace
}


* Tables 42 and 43
qui{
clear
use "Data files/Benchmark.dta"
set more off
keep if age<65 
keep if type2!=1 
	 
table  (education) if ESHI==0,  statistic(fvpercent tr_pay) nototals nformat(%5.2f)   
collect title "Has Health Shock, No ESHI, ages 25-64, Model"
collect export "${out_tables}/Pay_treat_Sim3.tex", tableonly replace

table  (education) if ESHI==1,  statistic(fvpercent tr_pay) nototals nformat(%5.2f)  
collect title "Has Health Shock, Has ESHI, ages 25-64, Model"
collect export "${out_tables}/Pay_treat_Sim4.tex", tableonly replace
}


* Table 44
qui{
clear
use "Data files/Benchmark.dta"
keep if age<65
table  H education if ESHI==0 & type2!=1 , statistic(mean I_treat)  nformat(%5.2f) 
collect title "Fraction who Treat Conditional on Health Shock, by Health, No ESHI, ages 25-64, Model"
collect export "${out_tables}/Fraction_treat.tex", tableonly replace
}




* Table 7 in paper, top panel - numbers slightly off
qui{

clear
use "Data files/Benchmark.dta"
keep if age<65 
gen col3= OOP if tr_pay_alt==1
replace col3=OOP if type2==1 // no shock. those with ESHI pay, and the uninsured have zero OOP
gen col4= MC*.6 - OOP if I_treat==1 & ESHI==1 //if you get Medicaid, they only cover what's left after ESHI
gen col5=OOP  if tr_pay_alt==2  // public
gen col6 =OOP if tr_pay_alt==3 // unpaid bills
gen col7=OOP if tr_pay_alt==4 // OOP if all got treated

gen count=1

collapse (sum) col*  count
replace col3=col3/count
replace col4=col4/count
replace col5=col5/count
replace col6=col6/count
replace col7=col7/count
drop count
save "Data files\Bills_All.dta", replace

clear
use "Data files/Benchmark.dta"
keep if age<65 

gen col3= OOP if tr_pay_alt==1
replace col3=OOP if type2==1 // no shock. those with ESHI pay, and the uninsured have zero OOP
gen col4= MC*.6 - OOP if I_treat==1 & ESHI==1 //if you get Medicaid, they only cover what's left after ESHI
gen col5=OOP  if tr_pay_alt==2  // public
gen col6 =OOP if tr_pay_alt==3 // unpaid bills
gen col7=OOP if tr_pay_alt==4 // OOP if all got treated

gen count=1

collapse (sum) col*  count, by(ESHI)

replace col3=col3/count
replace col4=col4/count
replace col5=col5/count
replace col6=col6/count
replace col7=col7/count

drop count
append using "Data files\Bills_All.dta"

label var col3 "OOP (Self)"
label var col4 "ESHI"
label var col5 "Medicaid"
label var col6 "Unpaid"
label var col7 "Untreated"

gen total= col3 + col4 + col5 + col6
label var total "Total if treated"

replace ESHI = 2 if ESHI==.
label define eshi_new 0 "No ESHI" 1 "ESHI" 2 "All"
label values ESHI eshi_new

table  (ESHI) ,  statistic(mean col3 col4 col5 col6 total col7)  nototals nformat(%5.0f)  
collect title "Average Medical Bills at ages 25-64"
collect export "${out_tables}/Bills_source.tex", tableonly replace
}



	
	
	
	


	
	 

